package com.hhkj.study.admin.dict.common;

import com.ruoyi.common.exception.GlobalException;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * LevelCode
 * top 第一级 second 第二级 third 第三级
 *
 * @author SERVER
 * @since 2024/3/27 18:45
 */
@Getter
@AllArgsConstructor
public enum LevelCodeEnum {
    TOP(1, "top"),
    SECOND(2, "second"),
    THIRD(3, "third"),
    FOUR(4, "four"),
    ;

    /** 排序序号 */
    private final Integer orderNum;

    /** 编码 */
    private final String code;

    public static LevelCodeEnum getTop() {
        return TOP;
    }

    /**
     * 获取下一级编码
     *
     * @param code 编码
     * @return 下一级枚举
     */
    public static LevelCodeEnum getNextByCode(String code) {
        LevelCodeEnum curentLevel = null;
        for (LevelCodeEnum levelCode : values()) {
            if (levelCode.code.equals(code)) {
                curentLevel = levelCode;
            }
        }
        if (curentLevel == null) {
            throw new GlobalException("不支持类型！");
        }
        Integer currentOrderNum = curentLevel.getOrderNum();
        Integer targetOrderNum = ++currentOrderNum;
        for (LevelCodeEnum levelCode : values()) {
            if (levelCode.orderNum.equals(targetOrderNum)) {
                return levelCode;
            }
        }
        return null;
    }
}
